package com.start.ad.mapper;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.start.ad.entity.StartAdContentEntity;
import com.start.ad.vo.StartAdContentVo;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StartAdContentMapper extends BaseMapper<StartAdContentEntity> {

    String AD_CONTENT_SQL = "SELECT * FROM (    " +
            "SELECT    " +
            "    saco.*,    " +
            "    saca.ad_category_name,     " +
            "    saca.ad_category_code,     " +
            "    saca.ad_category_cascade_code,     " +
            "    saca.ad_category_is_enable,    " +
            "    saca.ad_category_sort_num    " +
            "FROM    " +
            "    start_ad_content saco    " +
            "    INNER JOIN start_ad_category saca ON saca.ad_category_is_enable = 1     " +
            "    AND saco.ad_content_is_enable = 1     " +
            "    AND saco.ad_category_id = saca.id ) a ";

    @Select(AD_CONTENT_SQL + " ${ew.customSqlSegment} ")
    Page<StartAdContentVo> pageAdContent(@Param("page") Page<StartAdContentVo> page, @Param("ew") Wrapper<StartAdContentVo> queryWrapper);

    @Select(AD_CONTENT_SQL + " ${ew.customSqlSegment} ")
    List<StartAdContentVo> listAdContent(@Param("ew") Wrapper<StartAdContentVo> queryWrapper);
}
